package labox.innovation.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;

/**
 * 
 * @author bright
 *
 */
public class ConfigLoader {
    protected static final Logger _log = LoggerFactory.getLogger(ConfigLoader.class.getName());

    private static final String LOG_CONFIG_FILE = "./config/log.properties";

    public static void load() {
        
        //首先装载日志服务器
        loadLogServer();
        
        if (Server.serverMode == Server.MODE_GAMESERVER) {
            _log.info("Loading GameServer mode Configuration Files...", Config.SERVER_ID, "configfile");

            NetcoreConfig.load();
            TelnetConfig.load();
            NpcConfig.load();
            PvpConfig.load();
            RateConfig.load();
            ServerConfig.load();
            FloodprotectorConfig.load();
            L2jmodsConfig.load();

        } else if (Server.serverMode == Server.MODE_LOGINSERVER) {
            _log.info("Loading loginServer mode Configuration Files...", Config.SERVER_ID);
            
            LoginServerConfig.load();

        } else {
            _log.error("Could not Load Config: server mode was not set.", Config.SERVER_ID, null);
        }
    }

    private static void loadLogServer() {
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(lc);
            // the context was probably already configured by default
            // configuration rules
            lc.reset();
            configurator.doConfigure(LOG_CONFIG_FILE);
            _log.info("Loading LogSystem success!", Config.SERVER_ID, "LogSystem");
        } catch (Exception ex) {
            System.err.println("load LogSystem fail!check it!");
            ex.printStackTrace();
        }
    }
}
